function [residual] = kappa_iterative_residual_fixed_lambda( kp, par ) 
% Usage: kappa_iterative_residual_no_bankrun_model( kp, par ) 
% 
% Note: input kp should be a number. This function returns the residual of the jump equation of \kappa^p for the no
% bank run model.

beta=par.beta;  lambda=par.lambda;   alpha=par.alpha; varepsilon=par.varepsilon;  e=par.e;
max_jump = par.max_jump;   
w= par.w_ind;    xK_roots_fitted=par.xK_roots_fitted;   p_fitted=par.p_fitted;  
p = ppval( p_fitted, w );

if(w<1)
    xK = ppval( xK_roots_fitted, kp);  
    delta_x = beta*max(xK-1,0);
    kappab=(1-varepsilon)*(xK*kp+alpha*delta_x) + varepsilon*min(1-e, xK);
    kappa_fs = alpha*delta_x * w / (1-w);
    yK = (1-w*xK)/(1-w);
    kappah = varepsilon + (1-varepsilon)*yK*kp - kappa_fs;
    w_new = w .* (  1- kappab ) ./  ( 1- w*kappab - (1-w)*kappah )  ;
else
    w_new = w;
end

residual = p - ppval( p_fitted,  w_new   ) - kp  + 10^4*(kp<0 | kp>max_jump) ;